package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCDemo10 {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo());
        try (Connection connection = DBUtil.getConnection();) {
            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1, userInfo.getUserName());
            ps.setString(2, userInfo.getPassWord());
            ps.setString(3, userInfo.getNickName());
            ps.setInt(4, userInfo.getAge());
            int num = ps.executeUpdate();
            System.out.println(num > 0 ? "注册成功" : "注册失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
